home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 19.zip / BS1 part 19 / how to learn assembler.adf / CH4 / 4_3_2B-hex-bin2.asm < prev    next >
Assembly Source File  |  1988-02-25  |  827b  |  30 lines

  1. ;(4.3.2B) bin-hex2
  2. hexlong:
  3.      lea      buffer,a0      ; Pointer to the buffer
  4.      move.l   #$12345678,d1  ; Data we want to convert
  5.      move     #7,d3          ; Counter for the nibbles: 8-1
  6.  
  7. loop:
  8.      rol      #4,d1          ; Move upper nibble into lower
  9.      move     d1,d2          ; Write in d2
  10.      bsr      nibble         ; And convert it
  11.      move.b   d2,(a0)+       ; Character in buffer
  12.      dbra     d3,loop        ; Repeat 8 times
  13.      rts
  14.  
  15. nibble:
  16.      and      #$0F,d2        ; Just keep low byte
  17.      add      #$30,d2        ; Add $30
  18.      cmp      #$3A,d2        ; Was it a digit?
  19.      bcs      ok             ; Yes, done
  20.      add      #7,d2          ; Else add 7
  21.  
  22. ok:
  23.      rts                     ; Bye-bye
  24.  
  25. buffer:
  26.      DS.B 9                  ; Enough space for 8 hex digits and a null byte
  27.  
  28.      end
  29.  
  30.